package com.mayikt.subject.impl;

import com.mayikt.observer.ObServer;
import com.mayikt.subject.AbstractSubject;

import java.util.ArrayList;
import java.util.List;

public class WeChatSubject implements AbstractSubject {

    private List<ObServer> observerList = new ArrayList<ObServer>();
    private String message;

    public void addObServer(ObServer obServer) {
        observerList.add(obServer);
    }

    public void removeObServer(ObServer obServer) {
        observerList.remove(obServer);
    }

    public void notifyObServer(String message) {
        System.out.println("开始设置微信群发消息");
        // 调用观察则通知方法
        for (int i=0; i<observerList.size(); i++) {
            ObServer obServer = observerList.get(i);
            //调佣该方法通知 获取具体的消息
            obServer.update(message);
        }
    }
}
